﻿//------------------------------------------------------------------------------
// CCzoomr
//
// BuildServerProvider.cs
//
//------------------------------------------------------------------------------
// Copyright (c) 2007-2008, Scott Dorman (sj_dorman@hotmail.com)
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without 
// modification, are permitted provided that the following conditions are met:
// 
// * Redistributions of source code must retain the above copyright notice, 
//   this list of conditions and the following disclaimer.
// 
// * Redistributions in binary form must reproduce the above copyright notice, 
//   this list of conditions and the following disclaimer in the documentation 
//   and/or other materials provided with the distribution.
// 
// * Neither the name of CCzoomr (http://www.CCzoomr.com) nor the names of its 
//   contributors may be used to endorse or promote products derived from this
//   software without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE. 
//------------------------------------------------------------------------------
using System;
using System.Configuration.Provider;
using System.Collections.ObjectModel;

namespace CCzoomr.Configuration.Provider
{
    public abstract class BuildServerProvider : ProviderBase, IBuildServerProvider
    {
        #region events
        #endregion

        #region class-wide fields
        private Uri uri;
        #endregion

        #region private and internal properties and methods

        #region properties
        #endregion

        #region methods
        #endregion

        #endregion

        #region public properties and methods

        #region properties

        #region Uri
        /// <summary>
        /// Gets the URI of the current build server.
        /// </summary>
        /// <returns>The URI for the current build server.</returns>
        public virtual Uri Uri
        {
            get
            {
                return this.uri;
            }
            protected set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value", Properties.Resources.ArgumentNull_Obj);
                }
                this.uri = value;
            }
        }
        #endregion

        #region Description
        /// <summary>Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).</summary>
        /// <returns>A brief, friendly description suitable for display in administrative tools or other UIs.</returns>
        public sealed override string Description
        {
            get
            {
                return base.Description;
            }
        }
        #endregion

        #region Name
        /// <summary>Gets the friendly name used to refer to the provider during configuration.</summary>
        /// <returns>The friendly name used to refer to the provider during configuration.</returns>
        public sealed override string Name
        {
            get
            {
                return base.Name;
            }
        }
        #endregion

        #endregion

        #region methods

        #region ForceBuild
        public abstract void ForceBuild(string projectName);
        #endregion

        #region GetArtifactDirectory
        public abstract string GetArtifactDirectory(string projectName);
        #endregion

        #region GetBuildNames
        public abstract ReadOnlyCollection<String> GetBuildNames(string projectName);
        #endregion

        #region GetServerLog
        public abstract string GetServerLog();

        public abstract string GetServerLog(string projectName);
        #endregion

        #region GetServerVersion
        public abstract string GetServerVersion();
        #endregion

        #region InitializeCore
        protected void InitializeCore(string name, System.Collections.Specialized.NameValueCollection config, string description)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name", Properties.Resources.ArgumentNull_String);
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(Properties.Resources.Argument_StringZeroLength, "name");
            }

            if (null == config)
            {
                throw new ArgumentNullException("config", Properties.Resources.ArgumentNull_Obj);
            }

            if (description == null)
            {
                throw new ArgumentNullException("description", Properties.Resources.ArgumentNull_String);
            }

            if (description.Length == 0)
            {
                throw new ArgumentException(Properties.Resources.Argument_StringZeroLength, "description");
            }

            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", description);
            }

            base.Initialize(name, config);

            this.uri = new Uri(config["url"]);
        }
        #endregion

        #endregion

        #endregion
    }
}
